package com.tgy.leetcode;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Stack;

/**
 *
 * https://leetcode-cn.com/problems/clumsy-factorial/
 */
public class _1006_笨阶乘_01 {

    public static int clumsy(int N) {

        if (N == 1) {
            return 1;
        }

        /**
         * * / +  -
         */
        int index = 0;
        int val = N - 1;
        Stack<Integer> stack = new Stack<>();
        stack.push(N);
        while (val > 0) {

            int tmp = index % 4;
            switch (tmp) {
                case 0:
                    stack.push(stack.pop() * val);
                    break;
                case 1:
                    stack.push(stack.pop() / val);
                    break;
                case 2:
                    stack.push(val);
                    break;
                case 3:
                    stack.push(-val);
                    break;
                default:
            }

            index++;
            val--;
        }

        int res = 0;
        while (!stack.isEmpty()) {

           res += stack.pop();
        }

        return res;
    }

    public static void main(String[] args) {

        /**
         * 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1
         * 11 + 7 - 7+ 3 - 2
         * 11 + 7 - 7 + 1
         *
         */
        System.out.println(clumsy(10));
    }
}
